﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.ApplicationFramework;
using MyPublisher.Administration.ViewModels;

namespace MyPublisher.Administration.Views
{
    /// <summary>
    /// Interaction logic for MainView.xaml
    /// </summary>
    public partial class MainView : Window, IView
    {
        public MainView()
        {
            InitializeComponent();
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.Dispatcher.BeginInvoke((Action)delegate()
            {
                this.Model.Closed += new EventHandler(Model_DocumentClosed);
                this.Model.Opend += new EventHandler(Model_DocumentAdded);
            });
        }

        public MainViewModel Model { get { return DataContext as MainViewModel; } }

        void Model_DocumentAdded(object sender, EventArgs e)
        {
            if(splashView.Visibility == Visibility.Visible)
                splashView.Visibility = Visibility.Collapsed;
        }

        void Model_DocumentClosed(object sender, EventArgs e)
        {
            if (Model.DocumentViews.Count == 0)
                splashView.Visibility =  Visibility.Visible;
        }
    }
}
